<?php
//简单管理页面范例，在你的管理页面引用coresection/checkA.php就OK，
//当然，不要忘了添加注销登录的链接
include_once '../common/script/check_session.php';
?>


<?
if(isset($_REQUEST['sys_part']))
{
$system_part = $_REQUEST ['sys_part'];	
}


?>



<?
include_once("../../config_controller.php");
$host = $_SERVER['HTTP_HOST']; //取得进入所输入的域名
$theme_folder = host_theme($host);

include_once '../../front/' . $theme_folder . '/connection.php';include_once '../common/script/check_session.php';

?>

<?php include_once("function.php"); ?>
<?php include "../../front/" . $theme_folder . "/config.php"; ?>

<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/script/site-function.php"); ?>

<?
//20190601 取消这个文件include_once("detail-function.php")，后来发现，分类的数据，靠这个函数去获取。;
include_once("detail-function.php");
$detail=select_one_line_all_items($table_Prefix."detail","nid = '".$_REQUEST ['nid']."'");

$temp_erweima = json_decode($detail['erweima'],true);

$temp_erweima_link = explode('attr=',$temp_erweima['link']);

$select_link_attr = array();

if($temp_erweima_link[1]){
	
	foreach(explode($temp_erweima['link_code'],$temp_erweima_link[1]) as $val){
		$select_link_attr[] = $val;
	}
	
}

foreach($temp_erweima as $key=>$val){
	
	$erweima[] = $key;
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php include_once('../modules/head.php'); ?>



  
</head>

<body>

<div id="topbar">
    <!--TopBar端點01-->
    <?php include '../modules/topbar.php'; ?>
    <!--TopBar端點02-->
</div>

<div id="container">
<!--Container端點01-->
<div id="maincontent">
<!--maincontent端點01-->

<div id="sidebar">
    <?php include '../modules/sidebar.php'; ?>
</div>


<div id="content">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend><h1>编辑 : <? echo $detail['name'] ?>二维码设置 </h1></legend>
    </fieldset>

<div class="detail-box <? echo $system_part ?>">



<ul>

<form id="detail_detail_form" method="post"
      class="layui-form  layui-form-pane"
      action="erweima-edit-function.php?sys_part=<? echo $system_part ?>"
      name="uploadfile">



     <input type="hidden"  name="nid" value="<? echo $detail['nid']?>" >


    <fieldset class="layui-elem-field layui-field-title" id="content1" style="margin-top: 30px;">
        <legend>基本信息</legend>
    </fieldset>

    <blockquote class="layui-elem-quote">基本信息多数是对外使用的资料，请细心填写。</blockquote>
    <br/>




<li class="layui-form-item name">
    <label class="layui-form-label">名称：</label>
    <div class="layui-input-block">
        <input type="text" class="layui-input"  name="ai_name" readonly="readonly"  value="<? echo $detail['name'] ?>">
    </div>
    <em class="explain">(<u
            style="color:red">*必填项目</u>,
        填写标题)
    </em>
</li>




    <li class="layui-form-item publish">
        <label class="layui-form-label">设置链接：</label>
        
        <div class="layui-input-block">
            <input type="checkbox" lay-filter="sub_attr" class="attr_url" name="attr[url]" <?php if(in_array('url',$erweima)){echo 'checked="checked"';}?>  title="当前链接" value="<? echo $site_domin.'/'.$detail['url'] ?>.html">
          
        </div>
        
        <em class="explain"></em>
        
    </li>

    <li class="layui-form-item publish">
        <label class="layui-form-label">设置参数：</label>
        
        <div class="layui-input-block">
          
            <input type="checkbox" lay-filter="sub_attr" class="attr_attr" name="attr[model]" <?php if(in_array('model',$erweima)){echo 'checked="checked"';}?> title="型号" value="<? echo $detail['model'] ?>">
            <input type="checkbox" lay-filter="sub_attr" class="attr_attr" name="attr[introduce]" <?php if(in_array('introduce',$erweima)){echo 'checked="checked"';}?> title="简介" value="<? echo $detail['introduce'] ?>">
            <input type="checkbox" lay-filter="sub_attr" class="attr_attr" name="attr[name]" <?php if(in_array('name',$erweima)){echo 'checked="checked"';}?> title="名称" value="<? echo $detail['name'] ?>">
        </div>
        
        <em class="explain"></em>
        
    </li>




    <li class="layui-form-item link"><label class="layui-form-label">跳转地址：</label>

        <div class="layui-input-block"><input type="text"  class="layui-input attr_link" name="attr[link]"    value="<? echo $temp_erweima['link'] ?>"></div><em class="explain"></em>
    </li>
    <li class="layui-form-item link"><label class="layui-form-label">参数分隔符：</label>

        <div class="layui-input-block"><input type="text"  class="layui-input attr_link_code" name="attr[link_code]"    value="<? echo $link_code = $temp_erweima['link_code'] == '' ? '|' : $temp_erweima['link_code'] ?>"></div><em class="explain"></em>
    </li>
    <li class="layui-form-item publish">
        <label class="layui-form-label">跳转参数：</label>
        
        <div class="layui-input-block">
          
            <input type="checkbox" lay-filter="link_attr" class="link_attr" name="link_attr[model]" <?php if(in_array($detail['model'],$select_link_attr)){echo 'checked="checked"';}?>   title="型号" value="<? echo $detail['model'] ?>">
            <input type="checkbox" lay-filter="link_attr" class="link_attr" name="link_attr[introduce]" <?php if(in_array($detail['introduce'],$select_link_attr)){echo 'checked="checked"';}?> title="简介" value="<? echo $detail['introduce'] ?>">
            <input type="checkbox" lay-filter="link_attr" class="link_attr" name="link_attr[name]" <?php if(in_array($detail['name'],$select_link_attr)){echo 'checked="checked"';}?>  title="名称" value="<? echo $detail['name'] ?>">
        </div>
        
        <em class="explain"></em>
        
    </li>
    
    
    <li class="layui-form-item link"><label class="layui-form-label">当前效果：</label>
		<?php
		$attr = '';
		$jump_url = '';
		
		if(in_array('url',$erweima)){
			
			$attr .= $site_domin.'/'.$detail['url'].'.html';
		}
		
		if(in_array('name',$erweima)){
			$attr.=$attr != '' ? '|' : '';
			$attr .= 'name:'.$detail['name'];
		}
		
		if(in_array('model',$erweima)){
			$attr.=$attr != '' ? '|' : '';
			$attr .= 'model:'.$detail['model'];
		}
		if(in_array('introduce',$erweima)){
			$attr.=$attr != '' ? '|' : '';
			$attr .= 'introduce:'.$detail['introduce'];
		}
		
		if($temp_erweima['link']  != ''){
			$jump_url = $temp_erweima['link'];
		}
		?>
        <div class="layui-input-block">
        	<?php 
			if($jump_url != '' or $attr != ''){
				if($jump_url != ''){
			?>
        		<img src="<?php echo scerweima2($jump_url);?>" />
            <?php 
				}
				else{
			?>
            	<img src="<?php echo scerweima2($attr);?>" />
            <?php 
				}
			}
			?>
        </div>
    </li>



    <div class="function">
    	<button class="layui-btn " lay-submit lay-filter="formSub">立即提交</button>
       
        <input type="reset" class="layui-btn" value="重置"/>
		
        <input name="sys_part" type="hidden" value="<? echo $system_part ?>"/>
       
        
        <a href="javascript:;" class="layui-btn layui-bg-red layui-icon layui-icon-top go_top"></a>
    </div>
		

</form>
</ul>


</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>


<?php include  ROOT_PATH_."/controller/modules/footer.php"; ?>

<script type="text/javascript">
$(document).ready(function(e) {
    
	var attr_link_content = <?php echo isset($temp_erweima_link[1]) ? "'".$temp_erweima_link[1]."'" :"''" ?>;
	var attr_link_bak = $('.attr_link').val()
	var attr_link_code = $('.attr_link_code').val()
	
	
	
	layui.use('form', function(){
	  var form = layui.form;
	  	
		$('.attr_link_code').change(
			function(){
				
				attr_link_code = $(this).val()
			
				
				attr_link = $('.attr_link').val()
						
				reg1 = RegExp('attr=');
						
				is_has_attr_code = reg1.test(attr_link);
				
				if(is_has_attr_code == true){
					
					new_attr_link = getCaption(attr_link,0,'?');
						
					$('.attr_link').val(new_attr_link)
					
					$('.link_attr').attr('checked', false);
					attr_link_bak = new_attr_link;
					attr_link_content = '';
					form.render();
				}
			}
		)
		
	  	form.on('checkbox(sub_attr)', function(data){
		  now_name = data.elem.name; //得到checkbox原始DOM对象
		  now_check = data.elem.checked; //是否被选中，true或者false
			if(now_name == 'attr[url]' && now_check == true){
				$('.attr_attr').attr('checked', false);
				$('.attr_link').attr("readonly","readonly")
				$('.link_attr').attr('checked', false);
			}
			else if(now_name == 'attr[url]' && now_check == false){
				$('.attr_attr').attr('checked', false);
				$('.attr_link').attr("readonly",false)
				$('.link_attr').attr('checked', false);
			}
			
			if(now_name != 'attr[url]' && now_check == true){
				$('.attr_url').attr('checked', false);
				$('.attr_link').attr("readonly","readonly")
				$('.link_attr').attr('checked', false);
			}
			else if(now_name != 'attr[url]' && now_check == false){
				$('.attr_url').attr('checked', false);
				$('.attr_link').attr("readonly",false)
				$('.link_attr').attr('checked', false);
			}
			
			form.render();
		});        
		
		$('.attr_link').click(function(){
			$('.attr_url').attr('checked', false);
			$('.attr_attr').attr('checked', false);
			
			$('.link_attr').attr('checked', false);
			$('.attr_link').attr("readonly",false)
			form.render();
		})
		
		form.on('checkbox(link_attr)', function(data){
		 	
			$('.attr_url').attr('checked', false);
			$('.attr_attr').attr('checked', false);
			
			
			attr_link = $('.attr_link').val()
					
			reg1 = RegExp('attr=');
					
			is_has_attr_code = reg1.test(attr_link);
					
		  	now_check = data.elem.checked; //是否被选中，true或者false
			if( now_check == true){
				
				
				if(attr_link == ''){
					layer.msg('请填写网址内容');
					$('.link_attr').attr('checked', false);
					form.render();
					return
				}
				else{
					if(data.value == ''){
						layer.msg('当前参数内容为空');
						now_name = $(this).attr('name');
						$(this).attr('checked', false);
						form.render();
						return
					}
					
					var str = attr_link_content;
					
					var reg = RegExp(data.value);
					
					is_has_attr = reg.test(str);
					
					
					if(is_has_attr == false){
						if(attr_link_content.length > 0){
							attr_link_content+=attr_link_code+data.value
						}
						else{
							attr_link_content+=data.value
						}
					}
					
				}
				if(attr_link_content.length > 0){
					
					new_attr_link = getCaption(attr_link,0,'?attr');
					
					if(is_has_attr_code == false){			
						$('.attr_link').val(attr_link+'?attr='+attr_link_content)	
					}
					else{

						$('.attr_link').val(new_attr_link+'?attr='+attr_link_content)
					}
					
				}
				
				$('.attr_attr').attr('checked', false);
				$('.attr_url').attr('checked', false);
			}
			else{
				
				attr_link_content= attr_link_content.replace(attr_link_code+data.value, "")
				attr_link_content= attr_link_content.replace(data.value, "")
				
			
				if(attr_link_content.length > 0){
				
					if(attr_link_content.indexOf(attr_link_code) == 0){
						
						attr_link_content= attr_link_content.replace(attr_link_code, "")
						
					}	
					

					new_attr_link = getCaption(attr_link,0,'?attr');
					if(is_has_attr_code == false){			
						$('.attr_link').val(attr_link_bak+'?attr='+attr_link_content)	
					}
					else{

						$('.attr_link').val(new_attr_link+'?attr='+attr_link_content)
					}
					
					
				}
				else{
					new_attr_link = getCaption(attr_link,0,'?');
					
					$('.attr_link').val(new_attr_link)
				}
			}
			
			form.render();
		});
	});
	
});



function getCaption(obj,state,code) {
    var index=obj.lastIndexOf(code);
    if(state==0){
        obj=obj.substring(0,index);
    }else {
        obj=obj.substring(index+1,obj.length);
    }
    return obj;
}

</script>

</body>
</html>
